import Vue from 'vue'
import App from './App'
import router from './router'
// 全局样式
import './assets/css/global.css'
// 引入字体图标样式
import './assets/fonts/iconfont.css'
// 引入 elementUI 组件
import ElementUI from 'element-ui'
// 引入axios
import axios from 'axios'

// 设置baseUrl
axios.defaults.baseURL = 'http://www.liulongbin.top:8888/api/private/v1/'
// 把axiso挂载到vue
Vue.prototype.$http = axios
// 拦截卫士
router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem('login')
  if (to.path === '/login') {
    console.log('进来了')
    console.log(!!token)
    if (token) return next('/home')
    next()
  } else {
    if (!token) return next('/login')
  }
  next()
})
Vue.config.productionTip = false
Vue.use(ElementUI)
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App)
})
